<?php
namespace app\api\model;

use think\Model;
use think\Db;
class Base extends Model
{
    public function selectList($table, $where)
    {
        $data = Db::name($table)->where($where)->select();
        return $data;
    }

    public function getselectList($table,$field='*',$where,$order='id desc')
    {
        $data = Db::name($table)->field($field)->where($where)->order($order)->select();
        return $data;
    }

    public function getPage($table,$field='*',$where,$order='id desc',$page =1,$limit =10)
    {
        $data = Db::name($table)->field($field)->where($where)->order($order)->page($page, $limit)->paginate($limit);
        return $data;
    }

    public function getAdd($table,$data)
    {
        $arr =Db::name($table)->insertGetId($data);
        return $arr;
    }

    public function getEdit($table,$where,$data)
    {
        $arr =Db::name($table)->where($where)->update($data);
        return $arr;
    }

    public function getDel($table,$where)
    {
        $data =Db::name($table)->delete($where);
        return $data;
    }

    public function getOne($table,$field ='*',$where){
        $data =Db::name($table)->field($field)->where($where)->find();
        return $data;
    }

    public function getWhereIn($table,$field ='*',$fields,$where){
        $data =Db::name($table)->field($field)->whereIn($fields,$where)->select();
        return $data;
    }

    public function getSetInc($table,$where,$field,$step){
        $data =Db::name($table)->where($where)->setInc($field,$step);
        return $data;
    }

    public function getSetDec($table,$where,$field,$step){
        $data =Db::name($table)->where($where)->setDec($field,$step);
        return $data;
    }

    public function getSetField($table,$where,$data){
        $data =Db::name($table)->where($where)->setField($data);
        return $data;
    }

    public function getValue($table,$where,$field)
    {
        $data =Db::name($table)->where($where)->value($field);
        return $data;
    }
}
